package cc.idoone.spring_boot_hello.cors.controller;

import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 * 细粒度 CORS 配置
 *
 * @author hemj
 * @version 2017/9/22
 */
@RestController
@RequestMapping(value = "/cors", method = RequestMethod.POST)
public class CorsController {

	@CrossOrigin(origins = "http://localhost:8080")
	@RequestMapping(value = "/hello")
	public HashMap<String, Object> cors(@RequestParam(required = false) String name) {
		HashMap<String, Object> map = new HashMap<String, Object>();
		map.put("title", "hello world");
		map.put("name", name);
		return map;
	}

	@RequestMapping(value = "/configuration")
	public HashMap<String, Object> get(@RequestParam(required = false) String name) {
		HashMap<String, Object> map = new HashMap<String, Object>();
		map.put("title", "hello world");
		map.put("name", name);
		return map;
	}
}
